package com.atmilan.quartz.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import com.atmilan.quartz.mapper.StoreCartMapper;
import com.atmilan.quartz.model.entity.crmeb.StoreCart;
import com.atmilan.quartz.service.IStoreCartService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
* @author Mr.Zhang
* @description StoreCartServiceImpl 接口实现
* @date 2020-05-28 edit by stivepeim 2020-7-4
*/
@Service
public class StoreCartServiceImpl extends ServiceImpl<StoreCartMapper, StoreCart> implements IStoreCartService {

    /**
     * 检测商品是否有效 更新购物车商品状态
     * @param productId 商品id
     * @return 跟新结果
     */
    @Override
    public boolean productStatusNotEnable(Integer productId) {
//        StoreProductResponse storeProductResponse = storeProductService.getByProductId(productId);
//        if(null == storeProductResponse) return false;
        StoreCart storeCartPram = new StoreCart();
        storeCartPram.setProductId(productId);

        LambdaQueryWrapper<StoreCart> lqw = new LambdaQueryWrapper<>();
        lqw.setEntity(storeCartPram);
    
        List<StoreCart> existStoreCartProducts = list(lqw);
        if(null == existStoreCartProducts) return false;
        existStoreCartProducts = existStoreCartProducts.stream().map(e->{
            e.setStatus(false);
            return e;
        }).collect(Collectors.toList());
        return updateBatchById(existStoreCartProducts);
    }

}

